from django.db import models

# Create your models here.

class Users(models.Model):
    username = models.CharField(max_length=30)
    password = models.CharField(max_length=80)
    phone    = models.CharField(max_length=11)
    email    = models.CharField(max_length=100,null=True)
    sex      = models.IntegerField(null=True)
    age      = models.IntegerField(null=True)
    # pic存图片文件
    pic      = models.CharField(max_length=100)
    #  0正常  1禁用  2删除
    state    = models.IntegerField(default=0)
    addtime  = models.DateTimeField(auto_now_add=True)

    class Meta:
        # 指定生成权限
        permissions = (
            ("show_users", "查看会员管理"),
            ("insert_users", "添加会员"),
            ("edit_users", "修改会员"),
            ("del_users", "删除会员"),
        )


# 分类模型
class Types(models.Model):
    name = models.CharField(max_length=20)
    pid  = models.IntegerField()
    path = models.CharField(max_length=50)

    class Meta:
        # 指定生成权限
        permissions = (
            ("show_types", "查看商品分类管理"),
            ("insert_types", "添加商品分类"),
            ("edit_types", "修改商品分类"),
            ("del_types", "删除商品分类"),
        )

# 商品模型
class Goods(models.Model):
    #  id tid    title price num addtime   info    pic  status              clicknum  
    #    所属分类  类别   价格  库存  添加数据  购买详情  图片 状态(上架,下架,热卖)     点击量       
    tid     = models.ForeignKey(to="Types", to_field="id")
    title   = models.CharField(max_length=255)
    price   = models.FloatField()
    num     = models.IntegerField()
    info    = models.TextField()
    pic     = models.CharField(max_length=100)
    #  status 状态 上架 热卖 下架 
    #               0   1   2
    status  = models.IntegerField(default=0)
    clicknum= models.IntegerField(default=0)
    addtime = models.DateTimeField(auto_now_add=True)

    class Meta:
        # 指定生成权限
        permissions = (
            ("show_goods", "查看商品管理"),
            ("insert_goods", "添加商品"),
            ("edit_goods", "修改商品"),
            ("del_goods", "删除商品"),
        )


# 地址模型
class Address(models.Model):
    uid  = models.ForeignKey(to="Users", to_field="id")
    addressname = models.CharField(max_length=20)
    address = models.CharField(max_length=100)
    addressphone = models.CharField(max_length=11)
    # False普通地址  True默认地址
    status = models.IntegerField(default=False)

    class Meta:
        # 指定生成权限
        permissions = (
            ("show_address", "查看地址管理"),
            ("insert_address", "添加地址"),
            ("edit_address", "修改地址"),
            ("del_address", "删除地址"),
        )

# 订单
class Order(models.Model):
    uid  = models.ForeignKey(to="Users", to_field="id")
    aid  = models.ForeignKey(to="Address", to_field="id")
    totalprice = models.FloatField()
    addtime = models.DateTimeField(auto_now_add=True)
    status = models.IntegerField(default=0)

    class Meta:
        # 指定生成权限
        permissions = (
            ("show_order", "查看订单管理"),
            ("insert_order", "添加订单"),
            ("edit_order", "修改订单"),
            ("del_order", "删除订单"),
        )
    
# 订单详情
class OrederInfo(models.Model):
    orderid  = models.ForeignKey(to="Order", to_field="id")
    goodsid  = models.ForeignKey(to="Goods", to_field="id")
    num     = models.IntegerField()
    price   = models.FloatField()


'''
# 订单
    id    uid    addressid   totalprice   status(0未付款 1未付款 代发货 2已收货 3取消订单)  addtime   
# 订单详情
    id   orderid goodis num price 
    1    1001     12    5   499
'''

